package com.easy.controller;

import com.easy.bean.Category;
import com.easy.bean.Receiveraddress;
import com.easy.bean.User;
import com.easy.service.ICategoryService;
import com.easy.service.IReceiveraddressService;
import com.easy.util.LayData;
import com.easy.util.Page;
import com.easy.util.SYS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;
@Controller
@RequestMapping("receiveraddress")
public class ReceiveraddressController {
    @Autowired
    IReceiveraddressService receiveraddressService;

    @RequestMapping("list")
    @ResponseBody
    public LayData getReceiveraddressList(Page page, String text){
        List<Receiveraddress> list=receiveraddressService.selectReceiveraddress(page,text);
        int count=receiveraddressService.ReceiveraddressCount(text);
        return new LayData(count,list);
    }

    @RequestMapping("delete")
    @ResponseBody
    public int deleteReceiveraddress(int id){
        return receiveraddressService.deleteReceiveraddress(id);
    }

    @RequestMapping("add")
    @ResponseBody
    public int addReceiveraddress(HttpSession session,Receiveraddress receiveraddress){
        User loginUser=(User)session.getAttribute(SYS.SHOPPING_LOGIN_USER);
        receiveraddress.setUserid(loginUser.getId());
        return receiveraddressService.addReceiveraddress(receiveraddress);
    }

    @RequestMapping("edit")
    @ResponseBody
    public int editReceiveraddress(HttpSession session,Receiveraddress receiveraddress){
        User loginUser=(User)session.getAttribute(SYS.SHOPPING_LOGIN_USER);
        receiveraddress.setUserid(loginUser.getId());
        return receiveraddressService.editReceiveraddress(receiveraddress);
    }

    @RequestMapping("get")
    @ResponseBody
    public List<Receiveraddress> getReceiveraddressById(HttpSession session, Integer isdefault, Integer id){
        User loginUser=(User)session.getAttribute(SYS.SHOPPING_LOGIN_USER);
        Integer userid=loginUser.getId();
        return receiveraddressService.getReceiveraddressById(userid,isdefault,id);
    }

}
